﻿

Imports System.Data.OleDb

Public Class English
    Inherits System.Web.UI.Page


    Protected Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Submit.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)

        Dim SqlString As String = "Insert into english([From],[Email],[Feedback]) Values (?,?,?)"

        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)

        cmd.CommandType = CommandType.Text

        cmd.Parameters.AddWithValue("From", Article_From.Text)
        cmd.Parameters.AddWithValue("Email", Article_Email.Text)
        cmd.Parameters.AddWithValue("Feedback", Article_Feedback.Text)

        oleDbConn.Open()

        cmd.ExecuteNonQuery()

        Response.Redirect("English.aspx")
    End Sub

    Protected Sub Article_From_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Article_From.TextChanged

    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        displayTable(Request.Params("sort"))

    End Sub
    Private Sub displayTable(ByVal sortby As String)
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)


        oleDbConn.Open()
        Dim cmdQuery As String

        Select Case sortby
            Case "From"
                cmdQuery = "SELECT * FROM english ORDER BY " & sortby
            Case "Email"
                cmdQuery = "SELECT * FROM english ORDER BY " & sortby
            Case Else
                cmdQuery = "SELECT * FROM english"

        End Select

        Dim dbcomm = New OleDbCommand(cmdQuery, oleDbConn)
        Dim dbread = dbcomm.ExecuteReader()

        Dim t As New Table

        Dim thr As New TableHeaderRow


        thr.Controls.Add(getHeaderCellWithText("From"))
        thr.Controls.Add(getHeaderCellWithText("Email"))

        t.Controls.Add(thr)

        While dbread.Read()
            Dim tr As New TableRow()

            tr.Controls.Add(getCellWithText(dbread.Item("From")))
            tr.Controls.Add(getCellWithText(dbread.Item("Email")))

            t.Controls.Add(tr)

            Dim tr2 As New TableRow

            tr2.Controls.Add(getWideCellWithText(dbread.Item("Feedback")))

            t.Controls.Add(tr2)

        End While

        PlaceHolder1.Controls.Add(t)


    End Sub


    Private Function getCellWithText(ByVal cellStr As String)
        Dim mycell As New TableCell
        'mycell.Text = cellStr
        mycell.Controls.Add(New LiteralControl("<B>" & cellStr & "</B>"))

        Return mycell
    End Function
    Private Function getWideCellWithText(ByVal cellStr As String)
        Dim mycell As New TableCell
        mycell.ColumnSpan = 3
        'mycell.Text = cellStr
        mycell.Controls.Add(New LiteralControl("<I>" & cellStr & "</I>"))

        Return mycell
    End Function

    Private Function getCellWithText(ByVal cellStr As String, ByVal UrlAddress As String)
        Dim mycell As New TableCell
        'mycell.Text = cellStr
        'mycell.Controls.Add(New LiteralControl("<B>" & cellStr & "</B>"))
        Dim h1 As New HyperLink
        h1.NavigateUrl = UrlAddress
        h1.Text = cellStr
        mycell.Controls.Add(h1)
        Return mycell
    End Function

    Private Function getHeaderCellWithText(ByVal cellStr As String)
        Dim mycell As New TableHeaderCell
        Dim hl As New HyperLink
        hl.Text = cellStr
        hl.NavigateUrl = "english.aspx?sort=" & cellStr
        mycell.Controls.Add(hl)
        Return mycell

    End Function
End Class